import time
import warnings
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

from common.configManager import local_config
from common.loggeManager import loggerM

class BrowserUtils:
    def __init__(self):
        #去除控制台警告
        warnings.filterwarnings("ignore",category=DeprecationWarning)
        self.driver_name = local_config.driver_name()

    def get_driver(self):
        driver = None
        if self.driver_name.lower()=="chrome":
            try:
                loggerM.info("正在打开谷歌浏览器：%s" % self.driver_name)
                driver = self.__get_chrome_driver()
            except:
                loggerM.error("打开谷歌浏览器失败：%s" % self.driver_name)
                raise
            else:
                loggerM.info("打开谷歌浏览器成功：%s" % self.driver_name)
        elif self.driver_name.lower() == 'firefox':
            try:
                loggerM.info("正在打开火狐浏览器：%s" % self.driver_name)
                driver = self.__get_firefox_driver()
            except:
                loggerM.error("打开火狐浏览器失败：%s" % self.driver_name)
                raise
            else:
                loggerM.info("打开火狐浏览器成功：%s" % self.driver_name)
        return driver

    def __get_chrome_driver(self):
        driver = webdriver.Chrome()
        return driver

    def __get_firefox_driver(self):
        driver = webdriver.Firefox()
        return driver


browser = BrowserUtils()

if __name__ == '__main__':
    browser.get_driver()
    time.sleep(4)


